1
|
|
|
define( |
2
|
|
|
['jquery', 'core/view', 'lodash', 'routing'], |
3
|
|
|
function($, ItemView, _, Routing) { |
4
|
|
|
"use strict"; |
5
|
|
|
|
6
|
|
|
return ItemView.extend({ |
7
|
|
|
clientForm: null, |
8
|
|
|
ui: { |
9
|
|
|
'clientChange': '#client-select-change', |
10
|
|
|
'clientSelect': '#client-select' |
11
|
|
|
}, |
12
|
|
|
events: { |
13
|
|
|
'click @ui.clientChange': 'clientChange', |
14
|
|
|
'change @ui.clientSelect': 'clientSelect' |
15
|
|
|
}, |
16
|
|
|
initialize: function() { |
17
|
|
|
this.template = _.bind(function() { |
18
|
|
|
return this.getOption('clientForm'); |
19
|
|
|
}, this); |
20
|
|
|
}, |
21
|
|
|
onRender: function() { |
22
|
|
|
if (!this.model.isEmpty()) { |
23
|
|
|
this.$('#client-select').hide(); |
24
|
|
|
} |
25
|
|
|
}, |
26
|
|
|
clientChange: function(event) { |
27
|
|
|
event.preventDefault(); |
28
|
|
|
|
29
|
|
|
this._toggleContactInfo(); |
30
|
|
|
}, |
31
|
|
|
clientSelect: function(event) { |
32
|
|
|
let val = $(event.target).val(); |
|
|
|
|
33
|
|
|
if (parseInt(val, 10) === parseInt(this.model.id, 10)) { |
34
|
|
|
this._toggleContactInfo(); |
35
|
|
|
return; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
if (_.isEmpty(val)) { |
39
|
|
|
return; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
this.showLoader(); |
43
|
|
|
|
44
|
|
|
$.getJSON( |
45
|
|
|
Routing.generate('_xhr_clients_info', {id: val, type: this.getOption('type')}), |
46
|
|
|
_.bind(function(data) { |
47
|
|
|
this.$('#client-select-container').html(data.content); |
48
|
|
|
this._toggleContactInfo(true); |
49
|
|
|
|
50
|
|
|
if (this.options.hideLoader) { |
51
|
|
|
this.hideLoader(); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
if (data.currency) { |
55
|
|
|
data.client = val; |
56
|
|
|
this.trigger('currency:update', data); |
57
|
|
|
} |
58
|
|
|
}, this) |
59
|
|
|
); |
60
|
|
|
}, |
61
|
|
|
_toggleContactInfo: function(show) { |
62
|
|
|
let clientSelect = this.$('#client-select'); |
|
|
|
|
63
|
|
|
clientSelect.toggle(); |
64
|
|
|
|
65
|
|
|
if (clientSelect.is(':visible')) { |
66
|
|
|
clientSelect.find('select').select2().select2('val', 0); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
if (!_.isUndefined(show)) { |
70
|
|
|
if (true === show) { |
71
|
|
|
this.$('#client-select-container').show(); |
72
|
|
|
} else { |
73
|
|
|
this.$('#client-select-container').hide(); |
74
|
|
|
} |
75
|
|
|
} else { |
76
|
|
|
this.$('#client-select-container').toggle(); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
}); |
80
|
|
|
}); |